package ThreadDemo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 故我
 * Date: 2023-10-09
 * Time: 21:38
 */
public class ThreadDemo16 {
    public static void main(String[] args) throws InterruptedException {
        Object object = new Object();
        Thread t1 = new Thread(()->{
            System.out.println("t1 wait 之前！");
            synchronized (object){
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t1 wait 之后！");
        });

        Thread t2 = new Thread(()->{
            System.out.println("t2 notify 之前！");
            //需要先获取锁，再进行唤醒
            synchronized (object){
                object.notify();
            }
            System.out.println("t2 notify 之后！");
        });

        t1.start();
        Thread.sleep(500);
        t2.start();
    }
}
